Crate jsonrpc_client[−][src]
Expand description
A macro-driven JSON-RPC client.
This crate offers a macro-driven approach to interacting with JSON-RPC APIs.
JSON-RPC itself is pretty lightweight, yet it is pretty verbose if you have to roll a client from scratch on top of say reqwest
.
This crate abstracts away this boilerplate by allowing you to define a trait that resembles the API you want to talk to. At the same time, we give full control the user over which HTTP client they want to use to actually send the request.
Example
#[cfg(all(feature = "macros", feature = "reqwest"))]
#[jsonrpc_client::api]
pub trait Math {
async fn subtract(&self, subtrahend: i64, minuend: i64) -> i64;
}
#[cfg(all(feature = "macros", feature = "reqwest"))]
#[jsonrpc_client::implement(Math)]
struct Client {
inner: reqwest::Client,
base_url: reqwest::Url,
}
#[cfg(all(feature = "macros", feature = "reqwest"))]
#[cfg(all(feature = "macros", feature = "reqwest"))]
let client = Client::new("http://example-jsonrpc.org/".to_owned())?;
client.subtract(10, 5).await?;
Backends
This crate supports several backends out of the box. Concretely:
- reqwest
- surf
- isahc
To use any (or all) of these backends, simply activate the corresponding feature-flag:
[dependencies]
jsonrpc_client = { version = "*", features = ["reqwest", "surf", "isahc"] }
Modules
Structs
A JSON-RPC error.
A JSON-RPC request.
A JSON-RPC response.
A parsed URL record.
Enums
Traits
A trait abstracting over how a request is actually sent to a server.